#include "ECommand.h"
#include "ECommandManager.h"
#include "EController.h"
#include "EVariant.h"
#include <iostream>
#include <vector>
#include <string>
#include <DefineCommon.h>
#include <EItem.h>
#include <EItemVisitor.h>

class TempListener 
{
public:
    virtual void msgReceived(int len) 
    { 
        /* ... */ 
        ELOG_INFO("len=%d", len);
    }
};

class TempListenerSub : public TempListener
{
public:
    virtual void msgReceived(int len) 
    { 
        /* ... */ 
        ELOG_INFO("Sub's len=%d", len);
    }
};


class TempController;
typedef SmartPtr(TempController) TempControllerPtr;
class TempController : public EController
{
public:
    TempController()
    {
    }
    virtual ~TempController()
    {
    }

    virtual void handleCommand(const ECommandPtr& command)
    { 
        /* ... */ 
        ELOG_INFO("command.getName()=%s", command->getName().data());
    }
};

int main_test_ECommand(int argc, const char *argv[])//_test_ECommand
{
    ELOG_INFO("ExeCommon test ECommand");

    ELOG_INFO("testing EDelegate---------");
    TempListener l;
    EDelegate(void (TempListener::*)(int)) d = MakeDelegate(&TempListener::msgReceived, l);
    d(42);

    TempListenerSub* lSub = new TempListenerSub;
    EDelegate(void (TempListener::*)(int)) dSub = MakeDelegate(&TempListener::msgReceived, *lSub);
    dSub(35);

    //testing pushing EDelegate in List 
    ELOG_INFO("testing pushing EDelegate in List------");
    EList<EDelegate(void (TempListener::*)(int))> listDel;
    listDel.push_back(dSub);
    listDel[0](35);
    

    //regist EController
    ELOG_INFO("testing ECommandManager--------");
    SmartPtr(TempController) controllerPtr = NewSmartPtr(TempController)();
    ECommandManager::instance()->registDelegate(MakeDelegate(&EController::handleCommand, *controllerPtr));

    //push ECommand
    SmartPtr(ECommand) commandPtr = NewSmartPtr(ECommand)();
    commandPtr->setName("tested command");
    ECommandManager::instance()->pushECommand(commandPtr);

    ECommandManager::instance()->processECommand();


    return 1;
}
